package cn.bellychang.leetcode.question744;

/**
 * @author ChangLiang
 * @date 2021/3/8
 */
public class Solution {

    public char nextGreatestLetter(char[] letters, char target) {
        if(letters[letters.length-1] <= target){
            return letters[0];
        }

        int begin = 0;
        int end = letters.length -1 ;
        while(begin<end){
            int mid = ((end-begin)>>2) + begin;
            if(letters[mid] <= target){
                begin = mid + 1;
            }else{
                end = mid;
            }
        }
        return letters[end];
    }
}
